# Python 2.6.4
# Project Euler, Problem 67
# Copyright 2010 Talha Zaman

f = open("triangle.txt")
t = []
l = f.readline()
while l != "":
    t.append([int(x) for x in l.split(" ")])
    l = f.readline()
f.close()

for i in range(len(t)-2, -1, -1):
    for j in range(0, len(t[i])):
        t[i][j] += max(t[i+1][j], t[i+1][j+1])

print t[0][0]
